package sjtu.ist.warehouse4ws.service;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import sjtu.ist.warehouse4ws.dao.UserDao;
import sjtu.ist.warehouse4ws.model.User;

import com.opensymphony.xwork2.ActionContext;

public class LoginServiceImpl implements LoginService{     
	private UserDao userDao;
	//依赖注入DAO组件的setter方法
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	//登陆
	public User login(String name, String password) {
		List<User> user=userDao.findByName(name);
		//List<Role> role=roleDao
		if(user.isEmpty())
			return null;
		/*if(user.get(0).getUserState()==false)
			return false;*/
		if(!user.get(0).getPassword().equals(password))
			return null;	
		
		return user.get(0);
	}

	public int getType(String name) {
		// TODO Auto-generated method stub
		List<User> user=userDao.findByName(name);
		if(user.isEmpty())return -1;		
		return 1;
	}
}
